package com.wjl.picture.user.model.enums;

import lombok.Getter;

@Getter
public enum UserRoleEnum {

    ROLE_USER(1, "user"),
    ROLE_ADMIN(2, "admin"),
    ROLE_BAN(3, "ban");
    private final Integer code;

    private final String value;

    UserRoleEnum(Integer code, String value) {
        this.code = code;
        this.value = value;
    }

    // 根据 code 获取对应的 value
    public static String getValueByCode(Integer code) {
        for (UserRoleEnum role : UserRoleEnum.values()) {
            if (role.code.equals(code)) {
                return role.value;
            }
        }
        throw new IllegalArgumentException("Invalid code: " + code);
    }

    public static Integer getCodeByValue(String value) {
        for (UserRoleEnum role : UserRoleEnum.values()) {
            if (role.value.equals(value)) {
                return role.code;
            }
        }
        throw new IllegalArgumentException("Invalid code: " + value);
    }
}

